}
_clear() {
+ if (this._cancellable) {
+ this._cancellable.cancel();
+ this._cancellable = null;
+ }
+
if (this._panelService)
this._panelService.destroy();
}
_onConnected() {
- this._ibus.list_engines_async(-1, null, this._initEngines.bind(this));
+ this._cancellable = new Gio.Cancellable();
+ this._ibus.list_engines_async(-1, this._cancellable,
+ this._initEngines.bind(this));
this._ibus.request_name_async(IBus.SERVICE_PANEL,
- IBus.BusNameFlag.REPLACE_EXISTING,
- -1, null,
- this._initPanelService.bind(this));
+ IBus.BusNameFlag.REPLACE_EXISTING, -1, this._cancellable,
+ this._initPanelService.bind(this));
}
_initEngines(ibus, result) {
- let enginesList = this._ibus.list_engines_async_finish(result);
- if (enginesList) {
+ try {
+ let enginesList = this._ibus.list_engines_async_finish(result);
for (let i = 0; i < enginesList.length; ++i) {
let name = enginesList[i].get_name();
this._engines.set(name, enginesList[i]);
}
this._updateReadiness();
- } else {
+ } catch (e) {
+ if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+ return;
+
+ logError(e);
this._clear();
}
}
_initPanelService(ibus, result) {
- let success = this._ibus.request_name_async_finish(result);
+ let success = false;
+ try {
+ success = !!this._ibus.request_name_async_finish(result);
+ } catch (e) {
+ if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+ return;
+ logError(e);
+ }
+
if (success) {
this._panelService = new IBus.PanelService({ connection: this._ibus.get_connection(),
object_path: IBus.PATH_PANEL });
} catch (e) {
}
// If an engine is already active we need to get its properties
- this._ibus.get_global_engine_async(-1, null, (i, result) => {
+ this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, result) => {
let engine;
try {
engine = this._ibus.get_global_engine_async_finish(result);
return;
}
- this._ibus.set_global_engine_async(id, this._MAX_INPUT_SOURCE_ACTIVATION_TIME,
- null, callback || null);
+ this._ibus.set_global_engine_async(id,
+ this._MAX_INPUT_SOURCE_ACTIVATION_TIME,
+ this._cancellable, (_bus, res) => {
+ try {
+ this._ibus.set_global_engine_async_finish(res);
+ } catch (e) {
+ if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+ logError(e);
+ }
+ if (callback)
+ callback();
+ });
}
preloadEngines(ids) {
this._ibus.preload_engines_async(
ids,
-1,
- null,
+ this._cancellable,
null);
this._preloadEnginesId = 0;
return GLib.SOURCE_REMOVE;
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported InputMethod */
-const { Clutter, GLib, GObject, IBus } = imports.gi;
+const { Clutter, GLib, Gio, GObject, IBus } = imports.gi;
const Keyboard = imports.ui.status.keyboard;
}
_onConnected() {
- this._ibus.create_input_context_async ('gnome-shell', -1, null,
- this._setContext.bind(this));
+ this._cancellable = new Gio.Cancellable();
+ this._ibus.create_input_context_async ('gnome-shell', -1,
+ this._cancellable, this._setContext.bind(this));
}
_setContext(bus, res) {
- this._context = this._ibus.create_input_context_async_finish(res);
+ try {
+ this._context = this._ibus.create_input_context_async_finish(res);
+ } catch (e) {
+ if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
+ logError(e);
+ this._clear();
+ }
+ return;
+ }
+
this._context.connect('commit-text', this._onCommitText.bind(this));
this._context.connect('delete-surrounding-text', this._onDeleteSurroundingText.bind(this));
this._context.connect('update-preedit-text', this._onUpdatePreeditText.bind(this));
}
_clear() {
+ if (this._cancellable) {
+ this._cancellable.cancel();
+ this._cancellable = null;
+ }
+
this._context = null;
this._hints = 0;
this._purpose = 0;
if (event.type() == Clutter.EventType.KEY_RELEASE)
state |= IBus.ModifierType.RELEASE_MASK;
- this._context.process_key_event_async(event.get_key_symbol(),
- event.get_key_code() - 8, // Convert XKB keycodes to evcodes
- state, -1, null,
- (context, res) => {
- try {
- let retval = context.process_key_event_async_finish(res);
- this.notify_key_event(event, retval);
- } catch (e) {
- log(`Error processing key on IM: ${e.message}`);
- }
- });
+ this._context.process_key_event_async(
+ event.get_key_symbol(),
+ event.get_key_code() - 8, // Convert XKB keycodes to evcodes
+ state, -1, this._cancellable,
+ (context, res) => {
+ try {
+ let retval = context.process_key_event_async_finish(res);
+ this.notify_key_event(event, retval);
+ } catch (e) {
+ if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+ log(`Error processing key on IM: ${e.message}`);
+ }
+ });
return true;
}
});